#!/usr/bin/env python

import sys
import xmlrpclib
try:
 	import pygtk
  	pygtk.require("2.0")
except:
  	pass
try:
	import gtk
  	import gtk.glade
except:
	sys.exit(1)

class OLPConnectGUI:

	def __init__(self):

		#Set the Glade file
		self.gladefile = "olpconnect.glade"  
	        self.wTree = gtk.glade.XML(self.gladefile) 

		self.filechooser=self.wTree.get_widget("ChooserWindow")
		#self.filechooser.visible=True
		self.filechooser.hide()

		#Create our dictionary and connect it
		dic = { "on_aboutmeadd_clicked" : self.aboutmeadd_clicked,
			"on_MainWindow_destroy" : gtk.main_quit,
			"on_submitbutton_clicked" : self.on_submitbutton_clicked }
		self.wTree.signal_autoconnect(dic)

	def createVBoxofPeople(self,friends):
		vbox=gtk.VBox()

		for entry in friends:
			temp=gtk.Button(entry[0])
			vbox.pack_start(temp)
			temp.show()

		vbox.show()

		return vbox

	def createVBoxofPosts(self,posts):
		vbox=gtk.VBox()

		for entry in posts:
			hbox=gtk.HBox()

			temptextview1=gtk.TextView()
			temptextview1.set_wrap_mode(gtk.WRAP_WORD)
			tempbuffer1=gtk.TextBuffer()
			tempbuffer1.set_text(entry[0])
			temptextview1.set_buffer(tempbuffer1)
			hbox.pack_start(temptextview1)

			temptextview2=gtk.TextView()
			temptextview2.set_wrap_mode(gtk.WRAP_WORD)
			tempbuffer2=gtk.TextBuffer()
			tempbuffer2.set_text(entry[1])
			temptextview2.set_buffer(tempbuffer2)
			hbox.pack_start(temptextview2)
			
			vbox.pack_start(hbox)
			temphline=gtk.HSeparator()
			vbox.pack_start(temphline)
			temphline.show()

			temphline=gtk.HSeparator()
			vbox.pack_start(temphline)
			temphline.show()
			hbox.show()
			temptextview1.show()
			temptextview2.show()

		vbox.show()

		return vbox

	def changeColors(self,Inner_Color,Outer_Color):
		self.mainwindow=self.wTree.get_widget("MainWindow")
		self.mainwindow.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Inner_Color))

		self.mainscroll=self.wTree.get_widget("mainscroll").get_child()
		self.mainscroll.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Inner_Color))

		self.profileview=self.wTree.get_widget("ProfileView")
		self.profileview.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Outer_Color))

	def displayProfileHeader(self,Profile_Name,About_Me,Image):
		self.profilenamelabel=self.wTree.get_widget("ProfileName")
		self.profilenamelabel.set_markup("<span size='28000'><b>"+Profile_Name+"</b></span>")

		self.aboutmetextview=self.wTree.get_widget("aboutmetextview")
		self.aboutmebuffer=gtk.TextBuffer()
		self.aboutmebuffer.set_text(About_Me)
		self.aboutmetextview.set_buffer(self.aboutmebuffer)

		self.profileimage=self.wTree.get_widget("ProfileImage")
		self.profileimage.set_from_file(Image)
		
	def aboutmeadd_clicked(self, widget):
		self.changeColors("White","Grey")
		self.displayProfileHeader("Testing","1,2,3,",None)
		self.filechooser=self.wTree.get_widget("ChooserWindow")
		#self.filechooser.visible=True
		self.filechooser.show()
		print "Hello World!"

	def on_submitbutton_clicked(self, widget):
		self.passbox=self.wTree.get_widget("passbox")
		self.password=self.passbox.get_text()
		print self.password

		#server=xmlrpclib.Server('http://localhost:8000')		
		#server.getProfile('00:01:02:03:04','sexyballs','00:01:02:03:04')
		
		(Profile_Name,About_Me,Inner_Color,Outer_Color,Image)=("Alex K","Age: 21\nLocation: Durham, NC\nStudent At: Duke University","#005FE4","#00b20d","profile.jpg")


		self.changeColors(Inner_Color,Outer_Color)

		self.displayProfileHeader(Profile_Name,About_Me,Image)

		self.classmatesscrolled=self.wTree.get_widget("classmates_scrolled")
		self.classmatesscrolled.add_with_viewport(self.createVBoxofPeople((('Name1','Mac1'),('Name2','Mac2'),('Name3','Mac3'),('Name4','Mac4'),('Name5','Mac5'),('Name6','Mac6'))))

		self.penpalsscroll=self.wTree.get_widget("penpalsscroll")
		self.penpalsscroll.add_with_viewport(self.createVBoxofPeople((('Name1','Mac1'),('Name2','Mac2'),('Name3','Mac3'),('Name4','Mac4'),('Name5','Mac5'),('Name6','Mac6'))))

		self.diaryscroll=self.wTree.get_widget("diaryscroll")
		self.diaryscroll.add_with_viewport(self.createVBoxofPosts((('DATE','TA child is a human being between birth and puberty; a boy or girl. The legal definition of "child" generally refers to a minor, otherwise known as a person younger than the age of majority. "Child" may also describe a relationship with a parent or authority figure, or signify group membership in a clan, tribe, or religion; it can also signify being strongly affected by a specific time, place, or circumstance, as in "a child of nature" or "a child of the Sixties."[1]'),('DATE','The United Nations Convention on the Rights of the Child defines a child as "every human being below the age of 18 years unless under the law applicable to the child, majority is attained earlier."[2]Biologically, a child is anyone in the developmental stage of childhood, between infancy and adulthood.'),('DATE','The age at which children are considered responsible for their own actions has also changed over time, and this is reflected in the way they are treated in courts of law. In Roman times, children were regarded as not culpable for crimes, a position later adopted by the Church. In the nineteenth century, children younger than seven years old were believed incapable of crime. Children from the age of seven were considered responsible for their actions. Hence, they could face criminal charges, be sent to adult prisons, and be punished like adults by whipping, branding or hanging. [5]'),('DATE','The age at which children are considered responsible for their own actions has also changed over time, and this is reflected in the way they are treated in courts of law. In Roman times, children were regarded as not culpable for crimes, a position later adopted by the Church. In the nineteenth century, children younger than seven years old were believed incapable of crime. Children from the age of seven were considered responsible for their actions. Hence, they could face criminal charges, be sent to adult prisons, and be punished like adults by whipping, branding or hanging. [5]'))))

		self.penpalscroll=self.wTree.get_widget("penpalscroll")
		self.penpalscroll.add_with_viewport(self.createVBoxofPosts((('DATE','TA child is a human being between birth and puberty; a boy or girl. The legal definition of "child" generally refers to a minor, otherwise known as a person younger than the age of majority. "Child" may also describe a relationship with a parent or authority figure, or signify group membership in a clan, tribe, or religion; it can also signify being strongly affected by a specific time, place, or circumstance, as in "a child of nature" or "a child of the Sixties."[1]'),('DATE','The United Nations Convention on the Rights of the Child defines a child as "every human being below the age of 18 years unless under the law applicable to the child, majority is attained earlier."[2]Biologically, a child is anyone in the developmental stage of childhood, between infancy and adulthood.'),('DATE','The age at which children are considered responsible for their own actions has also changed over time, and this is reflected in the way they are treated in courts of law. In Roman times, children were regarded as not culpable for crimes, a position later adopted by the Church. In the nineteenth century, children younger than seven years old were believed incapable of crime. Children from the age of seven were considered responsible for their actions. Hence, they could face criminal charges, be sent to adult prisons, and be punished like adults by whipping, branding or hanging. [5]'),('DATE','The age at which children are considered responsible for their own actions has also changed over time, and this is reflected in the way they are treated in courts of law. In Roman times, children were regarded as not culpable for crimes, a position later adopted by the Church. In the nineteenth century, children younger than seven years old were believed incapable of crime. Children from the age of seven were considered responsible for their actions. Hence, they could face criminal charges, be sent to adult prisons, and be punished like adults by whipping, branding or hanging. [5]'))))



if __name__ == "__main__":
	hwg = OLPConnectGUI()
	gtk.main()
